
#include <iostream>
#include <vector>
#include <string>


#include <project_config.h>

using namespace std;


void make_combinations(std::vector<std::string> &dict, const std::string &current, const std::string &range, int length, int index) {
    if (index == length) {
        dict.push_back(current);
        return;
    }

    for (char c : range) {
        make_combinations(dict, current + c, range, length, index + 1);
    }
}

std::vector<std::string> make_dict_list(int length, const std::string &passwd_range) {
    std::vector<std::string> dict;
    if (length <= 0 || passwd_range.empty()) {
        return dict; // Return empty vector if length is non-positive or range is empty
    }
    make_combinations(dict, "", passwd_range, length, 0);
    return dict;
}

void make_dict_console() {
    cout << "[INFO] 生成字典 " << endl;
    int length = stoi(trim(input("输入生成密码词典的长度: ")));
    string dict_content = input("输入密码包含的所有出现字符: ");    

    vector<string> list = make_dict_list(length , dict_content);
    
    ofstream file("./password_dict.txt");
    if (!file.is_open()) {
        std::cerr << "Error opening file: " << "password_dict.txt" << std::endl;
        return;
    }
    for (const std::string& str : list) {
        file << str << std::endl;
        file.flush();
    }
    file.close();
    cout << "[INFO] 字典生成成功: password_dict.txt ; 密码数量: " << list.size() << endl;
}